<?php

/**
 * Class for rendering an img element.
 *
 * @author Ian Clarence <ian.clarence@gmail.com>
 */
class ViewImg extends ViewHtmlElement {

    /**
     * The constructor.
     *
     * @param array $fields
     */
    public function __construct(array $fields = array()) {
        
        $fields["tag"] = "img";

        parent::__construct($fields);

        if (isset($this->fields["src"])) {
            $this->setAttribute("src", $this->getSrc());
        }

        if (isset($this->fields["alt"])) {
            $this->setAttribute("alt", $this->getAlt());
        }

        if (isset($this->fields["height"])) {
            $this->setAttribute("height", $this->getHeight());
        }

        if (isset($this->fields["width"])) {
            $this->setAttribute("width", $this->getWidth());
        }

    }
    
    /**
     * Returning an image element.
     * 
     * @param string $src
     * @param string $alt
     * @param int $width
     * @param int $height
     * @return \self 
     */
    public static function imgInit($src, $alt, $width = NULL, $height = NULL) {
        return new self(
            array(
                'src' => $src,
                'alt' => $alt,
                'width' => $width,
                'height' => $height
            )
        );
    }

}